﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json.Linq;
using park.Common;

namespace park.ModelCode
{
    public partial class DictionaryMdf : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!Page.IsPostBack)
            {
                BD();
            }
        }


        private void BD()
        {

            if (Request.QueryString["ID"] != null)
            {
                #region 正式代码
                string strID = Request.QueryString["ID"];
                cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();
                string strJson = sl.GetDictionaryById(strID);
                JObject obj = JObject.Parse(strJson);
                this.hidID.Value = obj["Dictionary"]["ID"].ToString();
                this.txbName.Text = obj["Dictionary"]["Name"].ToString();
                this.txbContentItem.Text = obj["Dictionary"]["ContentItem"].ToString();
                #endregion

                #region 测试代码
                //string strJson = ""
                //    + "{"
                //    + "\"Dictionary\":{"
                //    + "\"ID\":1,"
                //    + "\"Name\":\"调度巡检记录\","
                //    + "\"ContentItem\":\"已处理,贴罚单,误报,逃逸,特许\""
                //    + "}"
                //+ "}";
                //JObject obj = JObject.Parse(strJson);
                //this.hidID.Value = obj["Dictionary"]["ID"].ToString();
                //this.txbName.Text = obj["Dictionary"]["Name"].ToString();
                //this.txbContentItem.Text = obj["Dictionary"]["ContentItem"].ToString();
                #endregion
                
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            #region 正式代码
            string strName = this.txbName.Text;
            string strContentItem = this.txbContentItem.Text;
            string strID = this.hidID.Value;
            cn.linkit.epark.ServiceList sl = new cn.linkit.epark.ServiceList();
            bool flag = sl.UpdDictionary(strID, strName, strContentItem);
            string msg = flag ? "数据保存成功！" : "数据保存失败，请重试...";
            Page.ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "<script>alert('" + msg + "');</script>");
            #endregion

            #region 测试代码
            //string strName = this.txbName.Text;
            //string strContentItem = this.txbContentItem.Text;
            //string strID = this.hidID.Value;
            //bool flag = true;
            //string msg = flag ? "数据保存成功！" : "数据保存失败，请重试...";
            //Page.ClientScript.RegisterStartupScript(GetType(), Guid.NewGuid().ToString(), "<script>alert('" + msg + "');</script>");
            #endregion
        }
    }
}